package org.example.aienglishapp.service.speech.chapter;

import org.example.aienglishapp.entity.speech.chapter.Chapter;
import org.example.aienglishapp.mapper.speech.chapter.ChapterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Asus
 */
@Service
public class ChapterService {

    @Autowired
    private ChapterMapper chapterMapper;

    @Transactional(readOnly = true)
    public Chapter findById(Long chapterId) {
        return chapterMapper.findById(chapterId);
    }

    @Transactional(readOnly = true)
    public List<Chapter> findAll() {
        return chapterMapper.findAll();
    }

    @Transactional(readOnly = true)
    public List<Chapter> findByBookId(Long bookId) {
        return chapterMapper.findByBookId(bookId);
    }

    @Transactional(rollbackFor = {DataAccessException.class})
    public int insert(Chapter chapter) {
        return chapterMapper.insert(chapter);
    }

    @Transactional(rollbackFor = {DataAccessException.class})
    public int update(Chapter chapter) {
        return chapterMapper.update(chapter);
    }

    @Transactional(rollbackFor = {DataAccessException.class})
    public int deleteById(Long chapterId) {
        return chapterMapper.deleteById(chapterId);
    }
}